﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HighLowTriple7;
using HighLowTriple7.Entity;
using Utils;
using WebTriple7.Class;
using WebTriple7.Service;

namespace WebTriple7.UserControl
{
    public partial class ucTriple7 : System.Web.UI.UserControl
    {

        public BetGameResult OldSession = new BetGameResult();
        public int AccountId
        {
            set { ViewState["AccountId"] = value; }
            get
            {
                try
                {
                    return (Int32)ViewState["AccountId"];
                }
                catch
                {
                    return -1;
                }
            }
        }        
        public int TypeAccount
        {
            set { ViewState["TypeAccount"] = value; }
            get
            {
                try
                {
                    return (Int32)ViewState["TypeAccount"];
                }
                catch
                {
                    return -1;
                }
            }
        }
        public string UserName
        {
            set { ViewState["UserName"] = value; }
            get
            {
                try
                {
                    return (string)ViewState["UserName"];
                }
                catch
                {
                    return string.Empty;
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {            
            if (UserUtils.IsLogin)
            {
                try
                {
                    if ((UserUtils.Triple7AccessToken ?? "") == "")
                        UserUtils.Triple7AccessToken = Triple7.Instance(AccountId, UserName, TypeAccount);
                    string accessToken = UserUtils.Triple7AccessToken;
                    if (Triple7.GetGameStatus(accessToken) == 5)
                    {

                        OldSession.Info = Triple7.GetSessionInfo(accessToken);
                        OldSession.Rate = Triple7.GetRateConfig(OldSession.Info.AuCurrent + OldSession.Info.AgCurrent,
                                                                accessToken);
                        OldSession.Success = true;
                        OldSession.Mess = "";
                    }
                    else
                    {
                        OldSession.Info=new Triple7SessionInfo();
                        OldSession.Rate=new RateConfigEntity();
                        OldSession.Success = false;
                        OldSession.Mess = "Chưa đặt cược";                        
                    }
                }
                catch
                {
                    AccountSession.Logout();
                }
            }
            else
            {
                OldSession.Info = new Triple7SessionInfo();
                OldSession.Rate = new RateConfigEntity();
                OldSession.Success = false;
                OldSession.Mess = "Bạn chưa đăng nhập";     
            }
        }
    }
}